{% extends "base.html" %}

{% block title %}RapidShare Links Checker (codename Petra){% endblock %}

{% block jscss %}
<script type="text/javascript" src="/static_media/js/prototype/prototype.js"></script>
<script type="text/javascript" src="/static_media/js/checker.js"></script>
{% endblock %}

{% block content %}
	<div>
		<div>Put each link you want to check in a single line</div>
			<form action="/checker/check/" method="post">
				<div>
					<textarea name="link_list" rows="10" cols="50">
					</textarea>
				</div>
				<div><input type="submit" value="Check"/></div>
			</form>
		</div>
		<div>
			Or put a url and i could scan all radpidshare links for you:<br/>
			<form action="/checker/fetch/" method="post">
				<div><input type="text" name="url" size="50"/></div>
				<div><input type="submit" value="Fetch"/></div>
			</form>
		</div>
	</div>
{% if error %}
Check links supplied, seems there are some problem with them.
{% endif %}
{% if links %}
<script language="Javascript">
links = Array();

{%for link in links%}
links[{{forloop.counter0}}] = '{{link.url}}';
{% endfor %}

function downloadAllLinks(){
	var links_str = "";
	for(i=0;i<links.length;i++){
		links_str += links[i]+";"
	}

	//Make ajax request
	var request = new Ajax.Request('/downloads/addall/', { method:'get',
                                parameters: {enc: "json", links: links_str},
                                onSuccess: function(transport){
                                        var json = transport.responseText;
                                        obj = json.evalJSON();
                                        var text = "";
                                        if (obj.result == 1){
                                                text = "Downloads added succesfully";
                                        }
                                        else{
                                                text = "Could not add downloads";
                                        }
                                        $('all').update(text);
                                        }
                                });

}
</script>
Detected Links :{{links|length}}<br/>
<table border="0" cellpadding="10" cellspacing="10">
{%for link in links%}
	<tr>
		<td>{{link.url}}</td>
		<td>{% if link.valid %}
			Valid &nbsp; <div id="link_{{forloop.counter}}"><a href="#"
onClick="add_download('{{link.url}}','link_{{forloop.counter}}')">Add download</a></div>
		    {% else %}
			Invalid
		    {% endif %}
		</td>
	</tr>
{% endfor %}
</table>
<div id="all">
<a href="#" onClick="downloadAllLinks()">Download all links</a>
</div>
{% else%}
Could not find any link.
{% endif %}
{% endblock %}

{% block footer %} pie {% endblock %}
